package com.taptech.doufu.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.taptech.doufu.R;
import com.taptech.doufu.app.WeMediaApplication;
import com.taptech.doufu.bean.NovelSortBean;

import java.util.List;

/**
 * Created by ${LiYi} on 2017/1/4.
 */

public class NovelSortAdapter extends BaseAdapter {
    List<NovelSortBean> novelSortBeanList;
    private NovelSortBean selNovelSortBean;
    private Context mContext;
    public  NovelSortAdapter( Context mContext,List<NovelSortBean> novelSortBeanList){
        this.novelSortBeanList = novelSortBeanList;
        this.mContext = mContext;
    }

    public void setSelNovelSortBean(NovelSortBean selNovelSortBean){
        this.selNovelSortBean = selNovelSortBean;
    }
    @Override
    public int getCount() {
        return novelSortBeanList != null ? novelSortBeanList.size() : 0;
    }

    @Override
    public NovelSortBean getItem(int position) {
        return novelSortBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder = null;
        if(convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.sort_complex_item, null);
            viewHolder = new ViewHolder();
            viewHolder.titleTv = (TextView) convertView.findViewById(R.id.sort_complex_item_title);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder)convertView.getTag();
        }
        NovelSortBean  novelSortBean = novelSortBeanList.get(position);

        if(novelSortBean.equals(selNovelSortBean)){
            viewHolder.titleTv .setTextColor(WeMediaApplication.getInstance().getResources().getColor(R.color.personal_top_title_bg));
            viewHolder.titleTv .setBackgroundResource(R.drawable.sort_item_sel_bg);
        }else {
            viewHolder.titleTv .setTextColor(WeMediaApplication.getInstance().getResources().getColor(R.color.text_color_3));
            viewHolder.titleTv .setBackgroundResource(R.drawable.sort_item_bg);
        }
        viewHolder.titleTv .setText(novelSortBean.getTitle());

        return convertView;
    }


    public class ViewHolder {
        TextView titleTv;
    }

}
